Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lambda][rule] classifier nested type conversion bug #456

Merged
merged 2 commits into from
Nov 8, 2017

Conversation

ryandeivert
Copy link
Contributor

@ryandeivert ryandeivert commented Nov 8, 2017

to: @jacknagz
cc: @airbnb/streamalert-maintainers
size: small
resolves N/A

Background

Discovered an issue with nested type conversion where the schema would still pass even if a value of a nested key was not of the right type.

  1. Consider, for instance, you have this log defined in logs.json:
{
  "test:log_name": {
    "schema": {
      "key_01": "string",
      "key_02": "string"
    },
    "parser": "json",
    "configuration": {
      "json_path": "results[*]",
      "envelope_keys": {
        "host": "string",
        "ip": "string"
    }
  }
}
  1. And the incoming log looks like this:
{
  "host": "host_name",
  "ip": "0.0.0.0",
  "results": [
    {
      "key_01": "value_01",
      "key_02": "value_02"
    }
  ]
}
  1. When streamalert:envelope_keys is used and this log goes through classifying, the resulting log will look something like:
{
  "key01": "value_01",
  "key02": "value_02",
  "streamalert:envelope_keys": {
    "host": "host_name",
    "ip": "0.0.0.0"
  }
}
  1. And the schema that gets constructed during parsing this log will look something like this:
{
  "key01": "string",
  "key02": "string",
  "streamalert:envelope_keys": {
    "host": "string",
    "ip": "string"
  }
}

In the above schema definition (# 1) if you change the "host" key's value within "envelope_keys" to "integer", the parsing of this log will succeed, but will log the following error:

StreamAlert [ERROR]: Invalid schema. Value for key [host] is not an int: host_name

Changes

  • This change ensure that all value types defined will fail the parsing if the value does not match by returning the recursive result of StreamClassifier._convert_type from within the method.

Testing

Adding unit test to validate that a failed type conversion of a nested value will result in a classification failure.

@ryandeivert ryandeivert added this to the 1.6.0 milestone Nov 8, 2017
@ryandeivert ryandeivert force-pushed the ryandeivert-classifier-convert-type-bug branch from feb56be to 147b1ad Compare November 8, 2017 00:55
@airbnb airbnb deleted a comment from coveralls Nov 8, 2017
@ryandeivert ryandeivert changed the title [lambda][rule] classifier convert type bug [lambda][rule] classifier nested type conversion bug Nov 8, 2017
@ryandeivert ryandeivert force-pushed the ryandeivert-classifier-convert-type-bug branch from 147b1ad to b2a098e Compare November 8, 2017 17:55
@ryandeivert ryandeivert requested a review from jacknagz November 8, 2017 17:55
@airbnb airbnb deleted a comment from coveralls Nov 8, 2017
@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.583% when pulling b2a098e on ryandeivert-classifier-convert-type-bug into d0de528 on master.

Copy link
Contributor

@jacknagz jacknagz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good find!

@ryandeivert ryandeivert merged commit d0e31ec into master Nov 8, 2017
@ryandeivert ryandeivert deleted the ryandeivert-classifier-convert-type-bug branch November 8, 2017 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants